/* memread.cpp
 *
 * try to maximize bandwidth by bombarding with memcpy
 *
 * working set size <= cache size
 */

#include <omp.h>
#include "bench.h"
#include <assert.h>

#include <string.h>

#define AI 0

void stride(int* src, int startindex, int endindex, long num_accesses, int64_t block_size)
{
    //printf("In thread %d, startindex %d, endindex %d, num_accesses %ld\n", omp_get_thread_num(), startindex, endindex, num_accesses);
    int sum = 0;
    int index = startindex;
    int block_len = block_size / sizeof(int);

    volatile int dest;
    for (long i = 0; i < num_accesses; i++)
    {
        dest = src[index];

        sum += dest;

        index += block_len;
        if (index > endindex - block_len)
          index = startindex;
    }
    finaldest[omp_get_thread_num()] = sum;

    return;
}
